﻿function SuperMark_DeleteItem(e)
{
	var DeleteId = e.target.attributes["No"].nodeValue;
	var list = new Array();
	// 加载内容
	LoadStroage_SuperMark(function(data, conetxt){
		// 删除指定编号	
		var re = $.grep(data.list, function(n,i){
						if(!n.No){
							n.No = HelpTool_GUID();
							list.unshift(n);
							return false;
						}
						if(n.No != DeleteId){
							return true;
						}
						else{
							return false;
						}
					});

		// 保存内容
		var newdata ={};
		newdata.list = re.concat(list);
		newdata.Menu = data.Menu;
		SaveStroage_SuperMark(newdata, function(err){SuperMark_ShowSuperMark(newdata, false)});
	});
	
	e.stopPropagation();
}

function SuperMark_Click(e)
{
	var url = $(e.target).parents("li").filter(".supermarkItem").attr("url");
	if(url != ""){
		window.location.href = url;
	}	
}

function SuperMark_ShowSuperMarkItem(obj)
{
	var result = "<li class=\"supermarkItem\" url='"+ obj.URL +"'>	\
					<table style=\"width:100%;table-layout: fixed;\">	\
						<tr>	\
							<td rowspan=\"2\" width=\"55px\">"+HelpTool_Img(obj.Img)+"</td>	\
							<td width=\"270px\" style=\"text-overflow:ellipsis;white-space:nowrap;overflow:hidden;\">"+ HelpTool_EecorateKey(obj.Key) +"</td>	\
							<td rowspan=\"2\" width=\"20px\"><img class=\"supermarkdelete\" src=\"img/Delete.png\" No=\""+ obj.No +"\"/></td>	\
						</tr>	\
						<tr>	\
							<td width=\"275px\" style=\"text-overflow:ellipsis;white-space:nowrap;overflow:hidden;\">"+ obj.Title +"</td>	\
						</tr>	\
					</table>	\
				</li>	<hr/>";
	return result;
}

function SuperMark_ShowSuperMark(SuperMarkData, context)
{
	var result ="";
	for(var item in SuperMarkData.list) {
		result += SuperMark_ShowSuperMarkItem(SuperMarkData.list[item]);
	}
	
	$("#spuermarkresult").html(result);
	$(".supermarkdelete").click(SuperMark_DeleteItem);
	$(".supermarkItem").click(SuperMark_Click);
	
	if(context){
		if(SuperMarkData.Menu == 2){
			$("#spuermarkbox").hide();
			$("#bookmarkbox").show();
			bookmark_show();
		}
		else{
			$("#spuermarkbox").show();
			$("#bookmarkbox").hide();
		}
	}
}
